package com.deep.deepenterpise.common.redis;

import lombok.Getter;
import lombok.Setter;

/**
 * @author xyz
 * @description RedisKeyPrefix的抽象类，提供默认的过期时间和前缀
 * @time 2024/4/18 11:34
 */
@Setter
public abstract class BaseRedisKeyPrefix implements RedisKeyPrefix {

    private int expireSeconds;

    private String prefix;

    @Setter
    @Getter
    private String suffix;

    protected BaseRedisKeyPrefix(int expireSeconds, String prefix) {
        super();
        this.expireSeconds = expireSeconds;
        this.prefix = prefix;
    }

    @Override
    public int expireSeconds() {
        // 默认0代表永不过期
        return expireSeconds;
    }

    @Override
    public String getKey() {
        return this.getClass().getSimpleName() + ":" + prefix + suffix;
    }
}
